﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

using GalaSoft.MvvmLight.Ioc;

using HandyControl.Data;
using HandyControl.Tools;

using Stock.Service;
using Stock.Updater.ViewModel;

namespace Stock.Updater
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Register();
        }

        private void Register()
        {
            SimpleIoc.Default.Register<AppService>();
            SimpleIoc.Default.Register<EasyMoneyService>();
            SimpleIoc.Default.Register<AppConfigService>();

            SimpleIoc.Default.Register<MainViewModel>();

            SetSkin(0);
        }

        public void SetSkin(int type)
        {
            var skins0 = Resources.MergedDictionaries[0];
            skins0.MergedDictionaries.Clear();
            skins0.MergedDictionaries.Add(ResourceHelper.GetSkin((SkinType)type));

            skins0.MergedDictionaries.Add(new ResourceDictionary
            {
                Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
            });
            skins0.MergedDictionaries.Add(new ResourceDictionary
            {
                Source = new Uri("pack://application:,,,/Stock.Updater;component/Resources/Style/App.xaml")
            });

            Current.MainWindow?.OnApplyTemplate();
            ConfigHelper.Instance.SetWindowDefaultStyle();
            ConfigHelper.Instance.SetNavigationWindowDefaultStyle();
        }
    }
}
